package shopping;

import java.security.DrbgParameters;
import java.util.ArrayList;
import java.util.List;

public class ShoppingCart {
    private int capacity;
    private List<Product> products;

    public ShoppingCart(int capacity) {
        products = new ArrayList<>();
        capacity = 0;
    }
    public void addProduct(Product product) {
        for(Product p:products) {
            if (p.getName().equals(product.getName())) {
                p.setQuantity(p.getQuantity());
                break;
            }
        }
        products.add(product);
    }
    public void display() {
        for(Product p:products) {
            System.out.println("名称"+p.getName()+"种类"+p.getCategory()+"价格"+p.getPrice()+"数量"+p.getQuantity());
        }
    }
    public void removeProduct(Product product) {
        products.remove(product);
        capacity--;
    }
    public double getTotalPrice() {
        double totalPrice = 0;
        for(Product p:products) {
            totalPrice += p.getPrice()*p.getQuantity();
        }
        return totalPrice;
    }
}
